#!/usr/bin/env bash

#field=$1
rm -rf graphs
echo "Creating graphs..."
mkdir graphs

for field in age playlist playcount degree idx
do
    if [ $field == idx ]; then
	field="id"
    fi
    #echo $field
    if [ $field == "age" ]; then
	tag="age "
    else
	tag="$field|total samples"
    fi

    cat total.log | egrep "$tag" | awk 'BEGIN{FS=" = ";counter=0;n=0} {n=counter % 3; if(n==0){printf("%s",$2)}; if(n==1){printf(",%s,",$2)}; if(n==2){printf("%s\n",$2)}; counter++} END{}' > $field.csv


    gnuplot << EOF
set title "No. of samples against Average $field"
set datafile separator ","
set xlabel "Number of samples"
set ylabel "Average $field"

set style line 80 lt rgb "#808080"
set style line 81 lt 0
set style line 81 lt rgb "#808080"

set grid back linestyle 81
set border 3 back linestyle 80

set xtics nomirror rotate by -45
set ytics nomirror

set style line 1 lt rgb "#A00000" lw 3
set style line 2 lt rgb "#00A000" lw 3

set terminal pngcairo
set output "$field.png"

plot "$field.csv" using 1:2 title 'RW' with lines ls 1, "$field.csv" using 1:3 title 'RWRW' with lines ls 2

EOF
done

echo "done!"
rm *.csv
mv *.png graphs
